package leetcode;

public class eleventwo {
    public static int longestOnes(int[] nums, int k) {
        if(nums.length==0||nums==null){
            return -1;
        }
        int count=0;
        int left;
        int right;
        int max=0;
        int n=nums.length;
        for(left=0,right=0;right<n;right++){
            if(nums[right]==0){
                count++;
            }
            if(count>k){
                max=Math.max(max,right-left);
                while(count!=k){
//                while(count>k){
                    if(nums[left]==0){
                        count--;
                        left++;
                    }else{
                        left++;
                    }
                }
            }
            max=Math.max(max,right-left+1);
        }
        return max;

    }

    public static void main(String[] args) {
        int[] array={0,0,0,1};
        int i = longestOnes(array, 4);
        System.out.println(i);
    }
}
